package com.fc.v2.controller.gen;

import com.fc.v2.common.base.BaseController;
import com.fc.v2.common.domain.AjaxResult;
import com.fc.v2.common.domain.ResultTable;
import com.fc.v2.model.custom.Tablepar;
import com.fc.v2.model.auto.Lecturer;
import com.fc.v2.service.LecturerService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import static com.fc.v2.common.domain.AjaxResult.successData;

/**
 * 讲师表Controller
 * @ClassName: LecturerController
 * @author fuce
 * @date 2021-06-16 14:19:34
 */
@Api(value = "讲师表")
@Controller
@RequestMapping("/LecturerController")
public class LecturerController extends BaseController{
	
	private String prefix = "gen/lecturer";
	
	@Autowired
	private LecturerService lecturerService;
	
	
	/**
	 * 讲师表页面展示
	 * @param model
	 * @return String
	 * @author fuce
	 */
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/view")
	@RequiresPermissions("gen:lecturer:view")
    public String view(ModelMap model)
    {
        return prefix + "/list";
    }
	
	/**
	 * list集合
	 * @param tablepar
	 * @param searchText
	 * @return
	 */
	//@Log(title = "讲师表", action = "111")
	@ApiOperation(value = "分页跳转", notes = "分页跳转")
	@GetMapping("/list")
	@RequiresPermissions("gen:lecturer:list")
	@ResponseBody
	public ResultTable list(Tablepar tablepar,Lecturer lecturer){
		PageInfo<Lecturer> page=lecturerService.list(tablepar,lecturer) ; 
		return pageTable(page.getList(),page.getTotal());
	}
	
	/**
     * 新增跳转
     */
	@ApiOperation(value = "新增跳转", notes = "新增跳转")
    @GetMapping("/add")
    public String add(ModelMap modelMap)
    {
        return prefix + "/add";
    }
	
    /**
     * 新增保存
     * @param 
     * @return
     */
	//@Log(title = "讲师表新增", action = "111")
	@ApiOperation(value = "新增", notes = "新增")
	@PostMapping("/add")
	@RequiresPermissions("gen:lecturer:add")
	@ResponseBody
	public AjaxResult add(Lecturer lecturer){
		int b=lecturerService.insertSelective(lecturer);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	/**
	 * 讲师表删除
	 * @param ids
	 * @return
	 */
	//@Log(title = "讲师表删除", action = "111")
	@ApiOperation(value = "删除", notes = "删除")
	@DeleteMapping("/remove")
	@RequiresPermissions("gen:lecturer:remove")
	@ResponseBody
	public AjaxResult remove(String ids){
		int b=lecturerService.deleteByPrimaryKey(ids);
		if(b>0){
			return success();
		}else{
			return error();
		}
	}
	
	
	/**
	 * 修改跳转
	 * @param id
	 * @param mmap
	 * @return
	 */
	@ApiOperation(value = "修改跳转", notes = "修改跳转")
	@GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap map)
    {
        map.put("Lecturer", lecturerService.selectByPrimaryKey(id));

        return prefix + "/edit";
    }
	
	/**
     * 修改保存
     */
    //@Log(title = "讲师表修改", action = "111")
	@ApiOperation(value = "修改保存", notes = "修改保存")
    @RequiresPermissions("gen:lecturer:edit")
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Lecturer lecturer)
    {
        return toAjax(lecturerService.updateByPrimaryKeySelective(lecturer));
    }

	@ApiOperation(value = "查询机构的讲师", notes = "查询机构的讲师")
	@GetMapping("/getLecturerByMechanism")
	@ResponseBody
	public ResultTable getLecturerByMechanism(Tablepar tablepar,Integer mechanismId){
		PageInfo<Lecturer> page=lecturerService.getLecturerByMechanism(tablepar,mechanismId) ;
		return pageTable(page.getList(),page.getTotal());
	}

	@ApiOperation(value = "查询讲师详情", notes = "查询讲师详情")
	@GetMapping("/getLecturerInfo")
	@ResponseBody
	public AjaxResult getLecturerInfo(Integer mechanismId,Integer id){
		return successData(1, lecturerService.getLecturerInfo(mechanismId,id));
	}
}
